#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.biz.config;

import java.util.regex.Pattern;

/**
 * Created by well on 16/6/18.
 */
public class AppConfig {

    public static Pattern localParttern = Pattern.compile("avatar.*");
    public static Pattern urlParttern = Pattern.compile("http.*");
    public static Pattern numberParttern = Pattern.compile("${symbol_escape}${symbol_escape}d+?");

    private static String imgHost;

    private static String fileHost;

    private static String homeServer;
    private static String wapServer;

    private static String huanxinHost;
    private static String huanxinClientId;
    private static String huanxinClientSecret;
    private static String huanxinOrgName;
    private static String huanxinAppName;

    private static String runMode;
    private static String appName;

    private static String weixinAppId;
    private static String weixinAppSecret;
    private static String weixinAppKey;
    private static String weixinMchId;
    private static String weixinTransferCertificate;

    private static String weixinWapAccount;
    private static String weixinWapAppId;
    private static String weixinWapAppSecret;
    private static String weixinWapMchId;
    private static String weixinWapKey;


    private static String alipayPid;
    private static String alipayAppId;
    private static String alipaySellerEmail;
    private static String alipaySellerKey;
    private static String alipayWapKey;

    private static String qiniuBucketName;

    private static boolean sendSms;
    private static boolean sendWeixinMsg;
    private static String msgWeixinAppId;
    private static String msgWeixinOpenId;


    public static String getWapServer() {
        return wapServer;
    }

    public  void setWapServer(String wapServer) {
        AppConfig.wapServer = wapServer;
    }

    public static String getAppName() {
        return appName;
    }

    public  void setAppName(String appName) {
        AppConfig.appName = appName;
    }

    public static String getHomeServer() {
        return homeServer;
    }

    public  void setHomeServer(String homeServer) {
        AppConfig.homeServer = homeServer;
    }

    public static String getWeixinWapKey() {
        return weixinWapKey;
    }

    public  void setWeixinWapKey(String weixinWapKey) {
        AppConfig.weixinWapKey = weixinWapKey;
    }

    public static String getWeixinWapAccount() {
        return weixinWapAccount;
    }

    public  void setWeixinWapAccount(String weixinWapAccount) {
        AppConfig.weixinWapAccount = weixinWapAccount;
    }

    public static String getMsgWeixinAppId() {
        return msgWeixinAppId;
    }

    public  void setMsgWeixinAppId(String msgWeixinAppId) {
        AppConfig.msgWeixinAppId = msgWeixinAppId;
    }

    public static String getMsgWeixinOpenId() {
        return msgWeixinOpenId;
    }

    public  void setMsgWeixinOpenId(String msgWeixinOpenId) {
        AppConfig.msgWeixinOpenId = msgWeixinOpenId;
    }

    public static boolean isSendSms() {
        return sendSms;
    }

    public  void setSendSms(boolean sendSms) {
        AppConfig.sendSms = sendSms;
    }

    public static boolean isSendWeixinMsg() {
        return sendWeixinMsg;
    }

    public  void setSendWeixinMsg(boolean sendWeixinMsg) {
        AppConfig.sendWeixinMsg = sendWeixinMsg;
    }

    public static String getWeixinWapAppId() {
        return weixinWapAppId;
    }

    public  void setWeixinWapAppId(String weixinWapAppId) {
        AppConfig.weixinWapAppId = weixinWapAppId;
    }

    public static String getWeixinWapAppSecret() {
        return weixinWapAppSecret;
    }

    public  void setWeixinWapAppSecret(String weixinWapAppSecret) {
        AppConfig.weixinWapAppSecret = weixinWapAppSecret;
    }

    public static String getWeixinWapMchId() {
        return weixinWapMchId;
    }

    public  void setWeixinWapMchId(String weixinWapMchId) {
        AppConfig.weixinWapMchId = weixinWapMchId;
    }

    public static String getWeixinTransferCertificate() {
        return weixinTransferCertificate;
    }

    public  void setWeixinTransferCertificate(String weixinTransferCertificate) {
        AppConfig.weixinTransferCertificate = weixinTransferCertificate;
    }


    public static String getWeixinAppKey() {
        return weixinAppKey;
    }

    public  void setWeixinAppKey(String weixinAppKey) {
        AppConfig.weixinAppKey = weixinAppKey;
    }

    public static String getQiniuBucketName() {
        return qiniuBucketName;
    }

    public  void setQiniuBucketName(String qiniuBucketName) {
        AppConfig.qiniuBucketName = qiniuBucketName;
    }

    public static String getAlipayWapKey() {
        return alipayWapKey;
    }

    public  void setAlipayWapKey(String alipayWapKey) {
        AppConfig.alipayWapKey = alipayWapKey;
    }

    public static String getAlipaySellerEmail() {
        return alipaySellerEmail;
    }

    public void setAlipaySellerEmail(String alipaySellerEmail) {
        AppConfig.alipaySellerEmail = alipaySellerEmail;
    }

    public static String getAlipaySellerKey() {
        return alipaySellerKey;
    }

    public  void setAlipaySellerKey(String alipaySellerKey) {
        AppConfig.alipaySellerKey = alipaySellerKey;
    }

    public static Pattern getLocalParttern() {
        return localParttern;
    }

    public  void setLocalParttern(Pattern localParttern) {
        AppConfig.localParttern = localParttern;
    }

    public static String getAlipayPid() {
        return alipayPid;
    }

    public  void setAlipayPid(String alipayPid) {
        AppConfig.alipayPid = alipayPid;
    }

    public static String getAlipayAppId() {
        return alipayAppId;
    }

    public  void setAlipayAppId(String alipayAppId) {
        AppConfig.alipayAppId = alipayAppId;
    }

    public static String getWeixinAppId() {
        return weixinAppId;
    }

    public  void setWeixinAppId(String weixinAppId) {
        AppConfig.weixinAppId = weixinAppId;
    }

    public static String getWeixinAppSecret() {
        return weixinAppSecret;
    }

    public  void setWeixinAppSecret(String weixinAppSecret) {
        AppConfig.weixinAppSecret = weixinAppSecret;
    }

    public static String getWeixinMchId() {
        return weixinMchId;
    }

    public  void setWeixinMchId(String weixinMchId) {
        AppConfig.weixinMchId = weixinMchId;
    }

    public static String getRunMode() {
        return runMode;
    }

    public void setRunMode(String runMode) {
        this.runMode = runMode;
    }

    public static String getHuanxinOrgName() {
        return huanxinOrgName;
    }

    public  void setHuanxinOrgName(String huanxinOrgName) {
        AppConfig.huanxinOrgName = huanxinOrgName;
    }

    public static String getHuanxinAppName() {
        return huanxinAppName;
    }

    public  void setHuanxinAppName(String huanxinAppName) {
        AppConfig.huanxinAppName = huanxinAppName;
    }

    public static String getHuanxinHost() {
        return huanxinHost;
    }

    public  void setHuanxinHost(String huanxinHost) {
        AppConfig.huanxinHost = huanxinHost;
    }

    public static String getHuanxinClientId() {
        return huanxinClientId;
    }

    public  void setHuanxinClientId(String huanxinClientId) {
        AppConfig.huanxinClientId = huanxinClientId;
    }

    public static String getHuanxinClientSecret() {
        return huanxinClientSecret;
    }

    public  void setHuanxinClientSecret(String huanxinClientSecret) {
        AppConfig.huanxinClientSecret = huanxinClientSecret;
    }

    public static String getFileHost() {
        return fileHost;
    }

    public  void setFileHost(String fileHost) {
        AppConfig.fileHost = fileHost;
    }

    public static String getImgHost() {
        return imgHost;
    }

    public  void setImgHost(String imgHost) {
        AppConfig.imgHost = imgHost;
    }


    public static String renderUrl(String relativePath){
        if(relativePath == null){
            return null;
        }
        if(imgHost.endsWith("/")){
            if(relativePath.startsWith("/")){
                return imgHost+relativePath.substring(1);
            }else{
                return imgHost+relativePath;
            }
        }else{
            if(relativePath.startsWith("/")){
                return imgHost+relativePath;
            }else{
                return imgHost+"/"+relativePath;
            }
        }
    }

    public static String subUrl(String url){
        if(url == null){
            return null;
        }
        int index  = url.indexOf(imgHost);
        if(index >= 0) {
            return url.substring(index);
        }else{
            return url;
        }
    }

    public static String renderFileUrl(String relativePath){
        if(relativePath == null){
            return null;
        }
        if(fileHost.endsWith("/")){
            if(relativePath.startsWith("/")){
                return fileHost+relativePath.substring(1);
            }else{
                return fileHost+relativePath;
            }
        }else{
            if(relativePath.startsWith("/")){
                return fileHost+relativePath;
            }else{
                return fileHost+"/"+relativePath;
            }
        }
    }



    /**
     * wap端本地头像不需要拼装
     * @param relativePath
     * @return
     */
    public static String renderUrlAndLocalForWap(String relativePath) {
        if(relativePath == null){
            return imgHost+"/assets/images/mobile/default_avatar.png";
        }
        if(localParttern.matcher(relativePath).matches()){
            return imgHost + "/assets/images/mobile/avatar/"+ relativePath.substring(6) + ".png";
        }
        if(numberParttern.matcher(relativePath).matches()){
            return imgHost + "/assets/images/mobile/avatar/"+ relativePath + ".png";
        }

        return renderUrl(relativePath)  ;

    }
}
